package com.songlanyun.modules.comment.controller.admin;

import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.comment.entity.UserComment;
import com.songlanyun.modules.comment.service.UserCommentService;
import com.songlanyun.modules.exception.MemberException;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 会员的评论
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-30 17:57:16
 */
@RestController
@RequestMapping("admin/comment/user")
public class UserCommentAdminController extends AbstractController {
    @Autowired
    private UserCommentService userCommentService;

    /**
     * 列表
     */
    @GetMapping("/list")
//    @RequiresPermissions("comment:userComment:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = userCommentService.findList(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @GetMapping("/page")
//    @RequiresPermissions("comment:userComment:list")
    public R page(@RequestParam Map<String, Object> params) {
        PageUtils page = userCommentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 作品评价列表
     */
    @GetMapping("/opus-comment-list")
    //@RequiresPermissions("opus:opus:info")
    public R opusCommentList(@RequestParam Map<String, Object> params) {
        PageUtils page = userCommentService.opusCommentPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 是否显示
     */
    @SysLog("评论是否显示")
    @PostMapping("/show")
    //@RequiresPermissions("opus:opus:info")
    public R show(@RequestBody UserComment userComment) {
        if (userComment.getId() == null || userComment.getIsShow() == null) {
            throw new RRException(MemberException.COMMENT_SHOW_NOT_EXIST);
        }
        userCommentService.show(userComment);

        return R.ok();
    }


    /**
     * 删除
     */
    @SysLog("删除评论")
    @DeleteMapping("/delete/{id}")
//    @RequiresPermissions("comment:userComment:delete")
    public R delete(@PathVariable("id") Long id) {
        verifyAdmin();//平台管理员才能删除
        userCommentService.removeById(id);

        return R.ok();
    }

}
